#include <string> 
#include <vector> 
#include <cmath>
#include <sstream> 
#include <iostream> 
#include <unordered_map>

using namespace std;

bool is_prime(int num)
{
    if (num < 2){
        return false;
    }
    for (int i = 2; i <= sqrt(num); i ++)
    {
        if(num % i == 0)
        {
            return false;
        }
    }
    return true;

}

int main() { 
    string s, w;
    getline(cin, s); 
    istringstream iss(s); 
    vector<string> v; 
    while (iss >> w) v.push_back(w); 
    unordered_map<std::string, string> numbers = {
        {"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"}, {"four", "4"},
        {"five", "5"}, {"six", "6"}, {"seven", "7"}, {"eight", "8"}, {"nine", "9"}
    };
    string num_str = "";
    int flag = 0;
    for(int i = 0; i < v.size(); i++)
    {
        if (numbers.count(v[i]) != 0){
            num_str += numbers[v[i]];
        }
        else{
            flag = 1;
            break;
        }
    }
    if (flag == 0)
    {
        int num = stoi(num_str);
        if(num >= 100 && num <= 999)
        {
            int lower = num;
            int upper = num;
            while(true)
            {
                lower--;
                upper++;
                if(is_prime(lower))
                {
                    cout << lower;
                    break;
                }
                if(is_prime(upper))
                {
                    cout << upper;
                    break;
                }
            }
        }
        else
        {
            cout << "Wrong input";
        }
    }
    else
    {
        cout << "Wrong input";
    }
    
}